package com.zhixiang.xaec.action.system;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.google.gson.Gson;
import com.zhixiang.core.command.QueryFilter;
import com.zhixiang.core.entity.TreeObj;
import com.zhixiang.core.web.action.BaseAction;
import com.zhixiang.xaec.entity.system.StaffPosition;
import com.zhixiang.xaec.service.system.StaffPositionService;
@Controller
@Scope("prototype")
public class StaffPositionAction extends BaseAction
{

    private static final long serialVersionUID = 5837939100750796819L;

    
    private StaffPosition staffPosition;
    
    @Autowired
    private StaffPositionService staffPositionService;

    public StaffPosition getStaffPosition()
    {
        return staffPosition;
    }

    public void setStaffPosition(StaffPosition staffPosition)
    {
        this.staffPosition = staffPosition;
    }
    
    public String list(){
        
        QueryFilter localQueryFilter = new QueryFilter(getRequest());
        List<StaffPosition>localList = this.staffPositionService.getAll(localQueryFilter);         
        setSuccess(true);
        setTotalCounts(localQueryFilter.getPagingBean().getTotalItems());
        //返回结果集
        setResult(localList);
        return SUCCESS;
    }
    
    public String get(){
        String id = getRequest().getParameter("id");
        if(!"".equals(id)&&id!=null){
            setResult(staffPositionService.get(Long.valueOf(id)));
        }
        return SUCCESS;
    }
    
    public String delete(){
        String[] ids = getRequest().getParameterValues("ids");
        staffPositionService.delete(ids);
        return SUCCESS;     
    } 
    
    public String save(){       
        staffPositionService.save(staffPosition);
        return SUCCESS;
    }
    
    public String treeLoad(){
        String id = getRequest().getParameter("nodeId");
        if("".equals(id)||id==null){
            id="1";
        }
        List<TreeObj> treeList=staffPositionService.treeLoad(id);
        //直接向页面输出字符串
        if(treeList!=null){
            outJsonString(new Gson().toJson(treeList));
        }       
        return SUCCESS;
    }
}
